import type { PageParam, PageResult } from '@vben/request';

import { requestClient } from '#/api/request';

export namespace CmtContentResourceApi {
  export interface Resource {
    id?: number;
    communityId?: number;
    merchantId?: number;
    resourceType?: number;
    name?: string;
    description?: string;
    filePath?: string;
    fileSize?: number;
    fileType?: string;
    category?: string;
    tags?: string;
    downloadCount?: number;
    viewCount?: number;
    sort?: number;
    status?: number;
    createTime?: string;
  }

  export interface ResourcePageReqVO extends PageParam {
    name?: string;
    resourceType?: number;
    category?: string;
    status?: number;
    createTime?: string[];
  }
}

export function getResourcePage(params: CmtContentResourceApi.ResourcePageReqVO) {
  return requestClient.get<PageResult<CmtContentResourceApi.Resource>>(
    '/cmt/content-resource/page',
    { params },
  );
}

export function getResource(id: number) {
  return requestClient.get<CmtContentResourceApi.Resource>(
    `/cmt/content-resource/get?id=${id}`,
  );
}

export function createResource(data: CmtContentResourceApi.Resource) {
  return requestClient.post('/cmt/content-resource/create', data);
}

export function updateResource(data: CmtContentResourceApi.Resource) {
  return requestClient.put('/cmt/content-resource/update', data);
}

export function deleteResource(id: number) {
  return requestClient.delete(`/cmt/content-resource/delete?id=${id}`);
}

export function deleteResourceList(ids: number[]) {
  return requestClient.delete(
    `/cmt/content-resource/delete-list?ids=${ids.join(',')}`,
  );
}

export function exportResource(params: CmtContentResourceApi.ResourcePageReqVO) {
  return requestClient.download('/cmt/content-resource/export-excel', { params });
}
